package cn.edu.lzu.dao;

import cn.edu.lzu.entity.ExamineItemType;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @PackageName: cn.edu.lzu.dao
 * @ClassName: ExamineItemTypeMapper
 * @Description: TODO
 * @Author: 张琦[QQ:3098086691]
 * @Date: 2019/12/11 14:56
 * @Version: 1.0
 */
@Mapper
public interface ExamineItemTypeMapper {
    //改造：操作应该判断所属单位（unitId）；

    @Select("select * from examine_item_type where is_deleted=0 and level=0 and unit_id=#{unitId}")
    List<ExamineItemType> selFirstLevelItemType(long unitId);

    @Select("select * from examine_item_type where is_deleted=0 and parent_id=#{parentId}")
    List<ExamineItemType> selItemTypesByParentId(int parentId);

    @Update("update examine_item_type set type_name=#{newName} where item_type_id=#{itemTypeId}")
    int updTypeNameById(String newName, int itemTypeId);

    @Select("select * from examine_item_type where is_deleted=0 and item_type_id=#{id}")
    ExamineItemType selExamineItemTypeById(int id);

    @Insert("insert into examine_item_type (item_type_id, type_name, level, parent_id, is_deleted, unit_id) values(default, #{typeName}, #{level}, #{parentId}, #{isDeleted}, #{unitId})")
    int insExamineItemType(ExamineItemType examineItemType);

    @Update("update examine_item_type set is_deleted=1 where item_type_id = #{itemTypeId} or parent_id = #{itemTypeId}")
    int delExamineItemTypesById(int itemTypeId);

    @Insert("insert into examine_item_type (item_type_id, type_name, level, parent_id, is_deleted, unit_id) values(default, #{typeName}, 0, 0, 0, #{unitId})")
    int insExamineItemTypeByNameAndUnitId(String typeName, long unitId);

    @Select("select * from examine_item_type where is_deleted=0 and level=1")
    List<ExamineItemType> selAllLevelEqualsOne(long unitId);

    @Select("select * from examine_item_type where is_deleted=0 and level=2 and unit_id=#{unitId} and parent_id=#{parentId}")
    List<ExamineItemType> selAllLevel2Types(int parentId, long unitId);

    @Select("select * from examine_item_type where is_deleted=0 and level=3 and parent_id=#{parentId} and unit_id=#{unitId}")
    List<ExamineItemType> selAllLevel3Types(int parentId, long unitId);

    @Select("select * from examine_item_type where is_deleted=0 and level=4 and parent_id=#{parentId} and unit_id=#{unitId}")
    List<ExamineItemType> selAllLevel4Types(int parentId, long unitId);

    @Select("select * from examine_item_type where is_deleted=0 and unit_id=#{unitId} and type_name=#{typeName}")
    ExamineItemType selLabExamineItemType(long unitId, String typeName);

}
